package day16.pack3;

import java.io.*;

public class Test1 {
    public static void main(String[] args) throws IOException {
        File sourceFile = new File("D:\\图片视频\\jmj.jpg");
        File destFile = new File("e:\\", sourceFile.getName());
        copy(sourceFile, destFile);
    }

    public static void copy(File sourceFile, File distFile) throws IOException {
        if (!sourceFile.exists()) return;
        if (!distFile.exists()) distFile.createNewFile();
        // 简化finally中的判断关闭代码，但凡实现了Closeable接口的，可以写在try括号中，系统帮你关
        try (InputStream is = new FileInputStream(sourceFile);
             OutputStream os = new FileOutputStream(distFile);) {
            byte[] data = new byte[1024 * 1024 * 10];
            int len = 0;
            while ((len = is.read(data)) != -1) {
                os.write(data, 0, len);
            }
        }
    }
}
